```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>买卖股票的最佳时机 | 算法可视化</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
        }
        .code-block {
            background-color: #2d3748;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow: hidden;
        }
        .profit-animation {
            transition: all 0.3s ease;
        }
        .profit-animation:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(245, 158, 11, 0.3);
            z-index: -1;
            transform: scaleX(0);
            transform-origin: left;
            transition: transform 0.3s ease;
        }
        .highlight:hover::after {
            transform: scaleX(1);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-6xl flex flex-col items-center">
            <div class="flex items-center mb-6">
                <i class="fas fa-chart-line text-3xl mr-3"></i>
                <h1 class="text-4xl md:text-5xl font-bold font-serif">买卖股票的最佳时机</h1>
            </div>
            <p class="text-xl md:text-2xl text-center max-w-3xl leading-relaxed">
                探索如何通过单遍扫描算法在股票交易中获得最大利润
            </p>
            <div class="mt-12 w-full max-w-4xl bg-white bg-opacity-20 rounded-xl p-6 backdrop-blur-sm">
                <div class="flex justify-between items-center mb-4">
                    <h3 class="text-xl font-semibold">示例分析</h3>
                    <span class="px-3 py-1 bg-white bg-opacity-30 rounded-full text-sm">输入: [7,1,5,3,6,4]</span>
                </div>
                <div class="flex items-end h-40">
                    <div class="flex-1 flex items-end justify-around">
                        <div class="w-12 bg-red-400 rounded-t-lg" style="height: 70%;" data-price="7"></div>
                        <div class="w-12 bg-green-400 rounded-t-lg" style="height: 10%;" data-price="1"></div>
                        <div class="w-12 bg-green-400 rounded-t-lg" style="height: 50%;" data-price="5"></div>
                        <div class="w-12 bg-green-400 rounded-t-lg" style="height: 30%;" data-price="3"></div>
                        <div class="w-12 bg-green-400 rounded-t-lg" style="height: 60%;" data-price="6"></div>
                        <div class="w-12 bg-green-400 rounded-t-lg" style="height: 40%;" data-price="4"></div>
                    </div>
                </div>
                <div class="flex justify-between mt-2 text-sm opacity-80">
                    <span>第1天</span>
                    <span>第2天</span>
                    <span>第3天</span>
                    <span>第4天</span>
                    <span>第5天</span>
                    <span>第6天</span>
                </div>
                <div class="mt-6 text-center">
                    <p class="text-lg">最佳策略: <span class="font-bold">第2天买入(1)</span> → <span class="font-bold">第5天卖出(6)</span></p>
                    <p class="text-2xl font-bold mt-2">最大利润: <span class="text-yellow-300">5</span></p>
                </div>
            </div>
        </div>
    </section>

    <!-- Content Section -->
    <section class="py-16 px-4 md:px-0">
        <div class="container mx-auto max-w-4xl">
            <div class="grid md:grid-cols-3 gap-8">
                <!-- Problem Description -->
                <div class="md:col-span-2">
                    <h2 class="text-3xl font-bold font-serif mb-6 text-gray-800">
                        <i class="fas fa-question-circle text-blue-500 mr-2"></i>题目描述
                    </h2>
                    <div class="prose max-w-none text-gray-700 leading-relaxed">
                        <p>给定一个数组，其中第 i 个元素是第 i 天的股票价格。如果你最多只允许完成一笔交易（即买入和卖出一支股票一次），设计一个算法来计算你所能获取的最大利润。</p>
                        <p class="font-medium mt-4">注意：你不能在买入股票前卖出股票。</p>
                        <div class="mt-6 p-4 bg-blue-50 rounded-lg border-l-4 border-blue-500">
                            <p class="font-semibold text-blue-800">示例：</p>
                            <p>输入: <code class="bg-blue-100 px-2 py-1 rounded">[7, 1, 5, 3, 6, 4]</code></p>
                            <p>输出: <code class="bg-blue-100 px-2 py-1 rounded">5</code></p>
                            <p class="mt-2">解释: 在第 2 天买入(价格=1)，第 5 天卖出(价格=6)，利润=5。</p>
                        </div>
                    </div>
                </div>

                <!-- Key Points -->
                <div class="md:col-span-1">
                    <div class="bg-white rounded-xl shadow-md overflow-hidden profit-animation">
                        <div class="bg-blue-500 text-white px-4 py-3">
                            <h3 class="text-lg font-bold flex items-center">
                                <i class="fas fa-lightbulb mr-2"></i>核心考点
                            </h3>
                        </div>
                        <div class="p-4">
                            <div class="flex items-start mb-3">
                                <div class="bg-yellow-100 text-yellow-800 rounded-full w-8 h-8 flex items-center justify-center mr-3">
                                    <i class="fas fa-brain"></i>
                                </div>
                                <div>
                                    <h4 class="font-bold text-gray-800">贪心算法</h4>
                                    <p class="text-sm text-gray-600">通过局部最优选择达到全局最优</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="bg-purple-100 text-purple-800 rounded-full w-8 h-8 flex items-center justify-center mr-3">
                                    <i class="fas fa-chart-bar"></i>
                                </div>
                                <div>
                                    <h4 class="font-bold text-gray-800">单遍扫描</h4>
                                    <p class="text-sm text-gray-600">O(n)时间复杂度的优雅解法</p>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="bg-white rounded-xl shadow-md overflow-hidden mt-6 profit-animation">
                        <div class="bg-green-500 text-white px-4 py-3">
                            <h3 class="text-lg font-bold flex items-center">
                                <i class="fas fa-clock mr-2"></i>复杂度分析
                            </h3>
                        </div>
                        <div class="p-4">
                            <div class="mb-3">
                                <div class="flex justify-between mb-1">
                                    <span class="font-medium text-gray-700">时间复杂度</span>
                                    <span class="bg-green-100 text-green-800 px-2 py-1 rounded-full text-xs font-bold">O(n)</span>
                                </div>
                                <p class="text-sm text-gray-600">只需遍历数组一次</p>
                            </div>
                            <div>
                                <div class="flex justify-between mb-1">
                                    <span class="font-medium text-gray-700">空间复杂度</span>
                                    <span class="bg-blue-100 text-blue-800 px-2 py-1 rounded-full text-xs font-bold">O(1)</span>
                                </div>
                                <p class="text-sm text-gray-600">只使用了常数级别的额外空间</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Solution Section -->
            <div class="mt-16">
                <h2 class="text-3xl font-bold font-serif mb-6 text-gray-800">
                    <i class="fas fa-code text-purple-500 mr-2"></i>解题思路
                </h2>
                
                <div class="prose max-w-none text-gray-700 leading-relaxed">
                    <p class="text-lg font-medium">核心思想：</p>
                    <p>维护一个最小价格 <span class="highlight font-mono">min_price</span> 和最大利润 <span class="highlight font-mono">max_profit</span>。遍历数组，更新 <span class="highlight font-mono">min_price</span> 为当前最小值，并计算当前价格与 <span class="highlight font-mono">min_price</span> 的差值更新 <span class="highlight font-mono">max_profit</span>。</p>
                    
                    <div class="mt-8">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">算法步骤：</h3>
                        <ol class="list-decimal pl-6 space-y-3">
                            <li><strong>初始化</strong>最小价格为无穷大，最大利润为0</li>
                            <li><strong>遍历</strong>价格数组中的每一天</li>
                            <li>如果当前价格<strong>小于</strong>最小价格，更新最小价格</li>
                            <li>否则，计算当前价格与最小价格的差值，如果<strong>大于</strong>最大利润则更新</li>
                            <li>遍历结束后返回最大利润</li>
                        </ol>
                    </div>

                    <div class="mt-10">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">示例代码：</h3>
                        <div class="code-block p-4 rounded-lg">
                            <pre class="text-sm md:text-base overflow-x-auto"><code class="language-python">def maxProfit(prices):
    min_price = float('inf')  # 初始化最小价格为无穷大
    max_profit = 0            # 初始化最大利润为0
    
    for price in prices:
        # 更新最小价格
        min_price = min(min_price, price)
        # 计算并更新最大利润
        max_profit = max(max_profit, price - min_price)
    
    return max_profit</code></pre>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Visualization Section -->
            <div class="mt-16">
                <h2 class="text-3xl font-bold font-serif mb-6 text-gray-800">
                    <i class="fas fa-project-diagram text-red-500 mr-2"></i>算法可视化
                </h2>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-6">
                    <div class="mermaid">
                        graph LR
                            A[开始] --> B[初始化 min_price=∞, max_profit=0]
                            B --> C[遍历价格数组]
                            C --> D{当前价格 < min_price?}
                            D -->|是| E[更新 min_price = 当前价格]
                            D -->|否| F[计算利润 = 当前价格 - min_price]
                            F --> G{利润 > max_profit?}
                            G -->|是| H[更新 max_profit = 利润]
                            G -->|否| C
                            E --> C
                            C --> I[遍历结束?]
                            I -->|否| C
                            I -->|是| J[返回 max_profit]
                    </div>
                </div>

                <div class="mt-8 grid md:grid-cols-2 gap-6">
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 profit-animation">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                            <i class="fas fa-thumbs-up text-green-500 mr-2"></i>算法优势
                        </h3>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>时间复杂度仅为O(n)，效率极高</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>空间复杂度O(1)，内存使用最优</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>代码简洁明了，易于理解和实现</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-white rounded-xl shadow-md overflow-hidden p-6 profit-animation">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                            <i class="fas fa-exclamation-triangle text-yellow-500 mr-2"></i>注意事项
                        </h3>
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-info-circle text-blue-500 mt-1 mr-2"></i>
                                <span>只能进行一次完整的买卖交易</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-info-circle text-blue-500 mt-1 mr-2"></i>
                                <span>必须先买入才能卖出</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-info-circle text-blue-500 mt-1 mr-2"></i>
                                <span>如果价格持续下跌，最大利润为0</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // 微交互效果
        document.querySelectorAll('.highlight').forEach(el => {
            el.addEventListener('mouseenter', () => {
                el.classList.add('font-bold');
            });
            el.addEventListener('mouseleave', () => {
                el.classList.remove('font-bold');
            });
        });
    </script>
</body>
</html>
```